package com.example.ceramics;

import android.content.Context;
import android.util.Log;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.example.ceramics.database.dao.IUserDao;
import com.example.ceramics.database.dao.UserDaoImpl;
import com.example.ceramics.entity.UserEntity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

import static org.junit.Assert.*;

@RunWith(AndroidJUnit4.class)
public class TestUser {

    private IUserDao userDao;

    @Before
    public void testPrepare() {
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
        userDao = new UserDaoImpl(appContext);
    }

    @Test
    public void testAddUser() {
        UserEntity user = new UserEntity("3", "1", "a", "小a", "1", "1",
                "云南", "曲靖", "富源", "没有","");
        int result = userDao.addUser(user);
        Log.d("aaa", "addUser result:" + result);
        assertEquals(1, result);
    }

    @Test
    public void testDeleteUser() {
        int result = userDao.deleteUser("1");
        assertEquals(result, 1);
    }

    @Test
    public void testUpdateAddress() {
        UserEntity user = new UserEntity();
        user.setAccount("2");
        user.setName("小b");
        user.setPhone("222");
        user.setAddressProvince("广西");
        user.setAddressCity("桂林");
        user.setAddressCounty("灵川县");
        user.setAddressDetail("可以");
        int result = userDao.updateAddress(user);
        assertEquals(1, result);
    }

    @Test
    public void testUpdateInfo() {
        UserEntity user = new UserEntity();
        user.setAccount("2");
        user.setNickname("小二");
        user.setPhone("223");
        user.setEmail("2111");
        user.setImg("");
        int result = userDao.updateInfo(user);
        assertEquals(1, result);
    }

    @Test
    public void testListAllUser() {
        List<UserEntity> users = userDao.listAllUser();
        for (UserEntity user : users) {
            Log.d("aaa","list:"+user);
        }
    }
}
